const express = require('express')
const fs = require('fs')
const config = require(process.cwd() + '/src/config/config')
const Game = require(process.cwd() + '/src/class/index')

let router = express.Router()

// 添加或删除一个Autotile
const doAction = async (req) => {
  let map = new Game.Map()
  await map.init(req.body.id)
  
  // 重命名地图
  await map.rename(req.body.newName)
  
  // 返回新数据
  return map.folder.settings
}

/* GET users listing. */
router.post('/', function(req, res) {
  doAction(req).then((data) => {
    res.json(data)
  })
  .catch((err) => {
    console.log(err)
    res.sendStatus(500)
  })
})

module.exports = router
